﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoreBDS;
using System.Text;
using CoreNhaDat;

namespace BatDongSan.Modules
{
    public partial class Uc_SearchBrokerDetail : System.Web.UI.UserControl
    {
        string _keyWord;
        int _loaiNhaDatId;
        int _nhaDatId;
        int _provinceId;
        int _wardId;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    _keyWord = Request.QueryString["key"];
                }
                catch
                {
                    _keyWord = "";
                }
                _loaiNhaDatId = Convert.ToInt32(Request.QueryString["loai"]);
                _nhaDatId = Convert.ToInt32(Request.QueryString["nhadat"]);
                _provinceId = Convert.ToInt32(Request.QueryString["tp"]);
                _wardId = Convert.ToInt32(Request.QueryString["quan"]);
                if (!IsPostBack)
                {
                    LoadProject(_loaiNhaDatId);
                }
            }
            catch { }
        }

        public void LoadProject(int LNDId)
        {
            try
            {
                _loaiNhaDatId = LNDId;
                nlit_LoaiNhaDat info = LoaiNhaDatBll.GetById(_loaiNhaDatId, Utility.strConnect);
                if (_loaiNhaDatId > 0)
                {
                    if (info.NhaDatId == 1)
                    {
                        lbTitle.Text = "NHÀ ĐẤT BÁN / " + info.Name.ToUpper();
                    }
                    else
                    {
                        lbTitle.Text = "NHÀ ĐẤT CHO THUÊ / " + info.Name.ToUpper();
                    }
                }
                else
                {
                    lbTitle.Text = "NHÀ ĐẤT";
                }

                //lbTitle.Text = FieldOfBusinessBll.GetName(_idField, Utility.strConnect).ToUpper();
                List<VG_Broker> list = BrokerBll.GetList(_keyWord, _loaiNhaDatId, _nhaDatId, _provinceId, _wardId, Utility.strConnect);
                rptBroker.DataSource = list;
                rptBroker.DataBind();
                if (rptBroker.Items.Count > 0)
                    pnEmptyData.Visible = false;
                else
                    pnEmptyData.Visible = true;
            }
            catch { }
        }

        protected void rptBroker_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    VG_Broker info = (VG_Broker)e.Item.DataItem;
                    Literal ltrImg = (Literal)e.Item.FindControl("ltrImg");
                    //hplImg.ImageUrl = "~/Images/Project/" + info.Img;
                    //hplImg.ToolTip = info.Name;
                    //hplImg.NavigateUrl = string.Format("~/ProjectDetail.aspx?id={0}", info.ProjectId);

                    ltrImg.Text = string.Format("<img src=\"/Images/Business/{0}\" width=\"120px\" height=\"82px\" />", info.Img);

                    Literal ltrInfo = (Literal)e.Item.FindControl("ltrInfo");
                    StringBuilder query = new StringBuilder();
                    query.AppendLine("<span><b>Tên:</b> " + info.Name + "</span>");
                    query.AppendLine("<span><b>Địa chỉ:</b> " + info.Address + "</span>");
                    query.AppendLine("<span><b>Điện thoại:</b> " + info.Phone + " | <b>Fax:</b> " + info.Fax + "</span>");
                    query.AppendLine("<span><b>Email:</b> " + info.Email + "</span>");
                    query.AppendLine("<span><b>Website:</b> " + info.Website + "</span>");

                    ltrInfo.Text = query.ToString();

                    HyperLink hplName = (HyperLink)e.Item.FindControl("hplName");
                    hplName.NavigateUrl = string.Format("~/BrokerDetail.aspx?id={0}", info.BrokerId);
                    hplName.Text = info.Name;
                }
            }
            catch { }
        }
    }
}